package com.lsh.oms.core.proxy.service;

import org.springframework.stereotype.Component;

/**
 * Project Name: lsh-oms
 *
 * @author peter
 * @date 18/4/25
 * 北京链商电子商务有限公司
 * Package
 * desc:
 */
@Component
@Deprecated
public class GoodsServiceProxy {

//    private static Logger logger = LoggerFactory.getLogger(GoodsServiceProxy.class);

//    @Autowired
//    private OrderQueryService orderQueryService;
//
//    @Autowired
//    private AtpProxy atpProxy;

//    @Value("${base.goods.server.path}")
//    private String goodsServiceUrl;


//    public Map<Long, Good> requestItem2Goods(Long orderCode, Long parentOrderCode, String providerId,Long venderId, String logSign) {
//        Long atpCode = orderCode;
//        if (parentOrderCode != null && parentOrderCode.compareTo(0L) > 0) {
//            atpCode = parentOrderCode;
//        }
//
//        logger.info("orderCode {},parentOrderCode {}", orderCode, parentOrderCode);
//        Map<String, AtpHoldDetail> atpHoldDetailMap = this.atpProxy.querySkuDcQtyMap(atpCode);
//
//        if (atpHoldDetailMap == null || atpHoldDetailMap.size() == 0) {
//            throw new BusinessException(ReturnCode.REQUEST_FAIL, "查询库存扣减信息失败");
//        }
//
//        logger.info("查询库存扣减信息返回结果 {}", JSON.toJSONString(atpHoldDetailMap));
//
//        List<OrderDetail> orderDetails = this.orderQueryService.findDetails(orderCode);
//        //已经验证过订单存在，所以此处不验证明细为空
//        Map<Long, List<Long>> orderDetailMap = new HashMap<>();
//        for (OrderDetail orderDetail : orderDetails) {
//
//            List<Long> skuList = orderDetailMap.get(orderDetail.getSkuCode());
//            if(CollectionUtils.isEmpty(skuList)){
//                skuList = new ArrayList<>();
//
//                orderDetailMap.put(orderDetail.getSkuCode(), skuList);
//            }
//            skuList.add(orderDetail.getGoodsCode());
//
////            orderDetailMap.put(orderDetail.getSkuCode(), orderDetail.getGoodsCode());
//        }
//
//        Map<Long, Good> codeAllMaps = new HashMap<>();
//        for (Map.Entry<String, AtpHoldDetail> entry : atpHoldDetailMap.entrySet()) {
//            String saleRule = entry.getKey();
//            String[] splitRules = saleRule.split(":");
//
//            if (splitRules.length == 3) {
//                String saleProviderId = splitRules[1];
//
//                if (!saleProviderId.equals(providerId)) {
//                    continue;
//                }
//            } else {
//                continue;
//            }
//
//            AtpHoldDetail atpHoldDetail = entry.getValue();
//            logger.info(logSign + " 开始 请求商品服务" + JsonUtils.obj2Json(atpHoldDetail));
//            Map<Long, Good> code2GoodsMaps = GoodsServiceUtils.getItem2GoodsMaps(atpHoldDetail, orderDetailMap, goodsServiceUrl, venderId, logSign);
//            logger.info(logSign + " 结束 请求商品服务返回信息" + JsonUtils.obj2Json(code2GoodsMaps));
//            if (code2GoodsMaps == null || code2GoodsMaps.isEmpty()) {
//                logger.info(logSign + ",商品服务获取为空,订单号:" + orderCode);
//                continue;
//            }
//
//            codeAllMaps.putAll(code2GoodsMaps);
//        }
//
//        return codeAllMaps;
//    }


//    /**
//     * 请求商品服务
//     *
//     * @param orderCode 请求数据
//     * @param logSign   唯一标识
//     * @return 返回信息
//     */
//
//    public Map<String, Good> requestCode2Goods(Long orderCode, Long parentOrderCode, String providerId, Long venderId, String logSign) {
//        Long atpCode = orderCode;
//        if (parentOrderCode != null && parentOrderCode.compareTo(0L) > 0) {
//            atpCode = parentOrderCode;
//        }
//
//        logger.info("orderCode {},parentOrderCode {}", orderCode, parentOrderCode);
//        Map<String, AtpHoldDetail> atpHoldDetailMap = this.atpProxy.querySkuDcQtyMap(atpCode);
//
//        if (atpHoldDetailMap == null || atpHoldDetailMap.size() == 0) {
//            throw new BusinessException(ReturnCode.REQUEST_FAIL, "查询库存扣减信息失败");
//        }
//
//        logger.info("查询库存扣减信息返回结果 {}", JSON.toJSONString(atpHoldDetailMap));
//        List<OrderDetail> orderDetails = this.orderQueryService.findDetails(orderCode);
//        //已经验证过订单存在，所以此处不验证明细为空
//        Map<Long, Long> orderDetailMap = new HashMap<>();
//        for (OrderDetail orderDetail : orderDetails) {
//            orderDetailMap.put(orderDetail.getSkuCode(), orderDetail.getGoodsCode());
//        }
//
//        Map<String, Good> codeAllMaps = new HashMap<>();
//        for (Map.Entry<String, AtpHoldDetail> entry : atpHoldDetailMap.entrySet()) {
//            String saleRule = entry.getKey();
//            String[] splitRules = saleRule.split(":");
//
//            if (splitRules.length == 3) {
//                String saleProviderId = splitRules[1];
//                if (!saleProviderId.equals(providerId)) {
//                    continue;
//                }
//            } else {
//                continue;
//            }
//
//            AtpHoldDetail atpHoldDetail = entry.getValue();
//            logger.info(logSign + " 开始 请求商品服务" + JsonUtils.obj2Json(atpHoldDetail));
//            Map<String, Good> code2GoodsMaps = GoodsServiceUtils.getCode2GoodMaps(atpHoldDetail, orderDetailMap, goodsServiceUrl, venderId, logSign);
//            logger.info(logSign + " 结束 请求商品服务返回信息" + JsonUtils.obj2Json(code2GoodsMaps));
//            if (code2GoodsMaps == null || code2GoodsMaps.isEmpty()) {
//                logger.info(logSign + ",商品服务获取为空,订单号:" + orderCode);
////                throw new BusinessException(ReturnCode.REQUEST_FAIL, "商品服务获取信息为空");
//                continue;
//            }
//
//            codeAllMaps.putAll(code2GoodsMaps);
//        }
//
//        return codeAllMaps;
//    }

}
